package com.cn.xiaonuo.common.validated.util;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.util.CollectionUtils;


/**
 * 参数校验，判断工具类
 * 校验过程中，不会对表达式进行校验，所以请确保表达式的正确性
 *
 * @author yuxue
 * @date 2019-05-11
 */
public class CheckUtil {

    /**
     * 判断value == null
     *
     * @param value   字段值
     * @param express 这里不需要，只是为了参数统一
     * @return true or false
     */
    public static Boolean isNull(Object value, String express) {
        if (null != value) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }


    /**
     * 判断value != null
     *
     * @param value   字段值
     * @param express 这里不需要，只是为了参数统一
     * @return true or false
     */
    public static Boolean isNotNull(Object value, String express) {
        if (null == value) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }


    /**
     * 判断value ==null || length size <= 0
     * 支持字符串判断
     * 支持集合判断
     */
    public static Boolean isEmpty(Object value, String express) {
        return !isNotEmpty(value, express);
    }


    /**
     * 判断value !=null && length、size > 0
     * 支持字符串判断
     * 支持集合判断
     */
    public static Boolean isNotEmpty(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String && "".equals(((String) value).trim())) {
            return Boolean.FALSE;
        }
        if (value instanceof Collection && CollectionUtils.isEmpty((Collection) value)) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }


    /**
     * 判断参数是否是 true
     * 支持Boolean类型
     * 支持String类型
     */
    public static Boolean isTrue(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof Boolean) {
            return (Boolean) value;
        }
        if (value instanceof String) {
            try {
                return Boolean.parseBoolean((String) value);
            } catch (Exception e) {
                return Boolean.FALSE;
            }
        }
        return Boolean.FALSE;
    }

    /**
     * 判断参数是否是 false
     * 支持Boolean类型
     * 支持String类型
     */
    public static Boolean isFalse(Object value, String express) {
        return !isTrue(value, express);
    }


    /**
     * 判断参数是否是一个日期
     * 支持Date类型
     * 支持LocalDate类型
     * 支持String类型，yyyy-MM-dd、yyyyMMdd、yyyy/MM/dd格式； 默认仅支持yyyy-MM-dd
     */
    public static Boolean isDate(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {      // 通常json格式参数，都是以字符串类型传递，优先判断
            // 验证参数，不能处理掉所有异常的符号
            // String v = ((String) value).trim().replaceAll("[-/\\s]", ""); 
            String v = ((String) value); //.replaceAll("[-/]", "");
            try {
                LocalDate.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                return Boolean.TRUE;
            } catch (Exception e) {
                return Boolean.FALSE;
            }
        }
        if (value instanceof Date) {
            return Boolean.TRUE;
        }
        if (value instanceof LocalDate) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }


    /**
     * 判断参数是否是一个日期
     * 支持Date类型
     * 支持LocalDateTime类型
     * 支持String类型，yyyy-MM-dd HH:mm:ss、yyyyMMddHHmmss、yyyy/MM/dd HH:mm:ss格式； 默认仅支持yyyy-MM-dd HH:mm:ss
     */
    public static Boolean isDateTime(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {   // 通常json格式参数，都是以字符串类型传递，优先判断
            String v = ((String) value); //.replaceAll("[-/]", "");  // 验证参数，不能处理掉所有异常的符号
            try {
                LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                return Boolean.TRUE;
            } catch (Exception e) {
                /*try {
                    LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                    return Boolean.TRUE;
                } catch (Exception e1) {
                    return Boolean.FALSE;
                }*/
                return Boolean.FALSE;
            }
        }
        if (value instanceof Date) {
            return Boolean.TRUE;
        }
        if (value instanceof LocalDateTime) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    /**
     * 判断参数是否是一个过去时间
     * 支持Date类型
     * 支持LocalDate类型
     * 支持LocalDateTime类型
     * 支持String类型，yyyy-MM-dd、yyyyMMdd、yyyy/MM/dd格式； 默认仅支持yyyy-MM-dd
     * 支持String类型，yyyy-MM-dd HH:mm:ss、yyyyMMddHHmmss、yyyy/MM/dd HH:mm:ss格式； 默认仅支持yyyy-MM-dd HH:mm:ss
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isPast(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {   // 通常json格式参数，都是以字符串类型传递，优先判断
            String v = ((String) value); //.replaceAll("[-/]", "");  // 验证参数，不能处理掉所有异常的符号
            if (v.length() <= 10) { // 日期
                try {
                    LocalDate ld = LocalDate.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    return LocalDate.now().isAfter(ld);
                } catch (Exception e) {
                    return Boolean.FALSE;
                }
            }
            try {
                LocalDateTime ldt = LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                return LocalDateTime.now().isAfter(ldt);
            } catch (Exception e) {
                /*try {
                    LocalDateTime ldt = LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                    return LocalDateTime.now().isAfter(ldt);
                } catch (Exception e1) {
                    return Boolean.FALSE;
                }*/
                return Boolean.FALSE;
            }
        }
        if (value instanceof Date) {
            return new Date().after((Date) value);
        }
        if (value instanceof LocalDate) {
            return LocalDate.now().isAfter((LocalDate) value);
        }
        if (value instanceof LocalDateTime) {
            return LocalDateTime.now().isAfter((LocalDateTime) value);
        }
        return Boolean.FALSE;
    }

    /**
     * 判断参数是否是一个将来时间
     * 支持Date类型
     * 支持LocalDate类型
     * 支持LocalDateTime类型
     * 支持String类型，yyyy-MM-dd、yyyyMMdd、yyyy/MM/dd格式; 默认仅支持yyyy-MM-dd
     * 支持String类型，yyyy-MM-dd HH:mm:ss、yyyyMMddHHmmss、yyyy/MM/dd HH:mm:ss格式； 默认仅支持yyyy-MM-dd HH:mm:ss
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isFuture(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {   // 通常json格式参数，都是以字符串类型传递，优先判断
            String v = ((String) value); // .replaceAll("[-/]", "");  // 验证参数，不能处理掉所有异常的符号
            if (v.length() <= 10) { // 日期
                try {
                    LocalDate ld = LocalDate.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    return LocalDate.now().isBefore(ld);
                } catch (Exception e) {
                    return Boolean.FALSE;
                }
            }
            try {
                LocalDateTime ldt = LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                return LocalDateTime.now().isBefore(ldt);
            } catch (Exception e) {
                /*try {
                    LocalDateTime ldt = LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                    return LocalDateTime.now().isBefore(ldt);
                } catch (Exception e1) {
                    return Boolean.FALSE;
                }*/
                return Boolean.FALSE;
            }
        }
        if (value instanceof Date) {
            return new Date().before((Date) value);
        }
        if (value instanceof LocalDate) {
            return LocalDate.now().isBefore((LocalDate) value);
        }
        if (value instanceof LocalDateTime) {
            return LocalDateTime.now().isBefore((LocalDateTime) value);
        }
        return Boolean.FALSE;
    }


    /**
     * 判断是否是今天的日期
     * 支持Date类型
     * 支持LocalDate类型
     * 支持String类型，默认仅支持yyyy-MM-dd
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isToday(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {   // 通常json格式参数，都是以字符串类型传递，优先判断
            String v = ((String) value); // .replaceAll("[-/]", "");  // 验证参数，不能处理掉所有异常的符号
            try {
                LocalDate ld = LocalDate.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                return LocalDate.now().equals(ld);
            } catch (Exception e) {
                return Boolean.FALSE;
            }
        }
        if (value instanceof Date) {
            return new Date().equals((Date) value);
        }
        if (value instanceof LocalDate) {
            return LocalDate.now().equals((LocalDate) value);
        }
        return Boolean.FALSE;
    }


    /**
     * 判断是否是邮箱
     * 使用正则表达式判断
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isEmail(Object value, String express) {
        if (isNull(value, express)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {
            String regEx = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher((String) value);
            if (m.matches()) {
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }

    /**
     * 判断参数的取值范围，逗号隔开，无空格；闭区间
     * 支持Integer、Long、Short、Float、Double、BigDecimal
     *
     * @param value
     * @param rangeStr
     * @return
     */
    public static Boolean inRange(Object value, String rangeStr) {
        if (isNull(value, rangeStr)) {
            return Boolean.FALSE;
        }
        if (null == rangeStr || "".equals(rangeStr)) {
            return Boolean.FALSE;
        }
        if (value instanceof Integer) {
            Integer begin = Integer.valueOf(rangeStr.split(",")[0]);
            Integer end = Integer.valueOf(rangeStr.split(",")[1]);
            Integer v = ((Integer) value);
            return begin <= v && v <= end;
        }
        if (value instanceof Long) {
            Long begin = Long.valueOf(rangeStr.split(",")[0]);
            Long end = Long.valueOf(rangeStr.split(",")[1]);
            Long v = ((Long) value);
            return begin <= v && v <= end;
        }
        if (value instanceof Short) {
            Short begin = Short.valueOf(rangeStr.split(",")[0]);
            Short end = Short.valueOf(rangeStr.split(",")[1]);
            Short v = ((Short) value);
            return begin <= v && v <= end;
        }
        if (value instanceof Float) {
            Float begin = Float.valueOf(rangeStr.split(",")[0]);
            Float end = Float.valueOf(rangeStr.split(",")[1]);
            Float v = ((Float) value);
            return begin <= v && v <= end;
        }
        if (value instanceof Double) {
            Double begin = Double.valueOf(rangeStr.split(",")[0]);
            Double end = Double.valueOf(rangeStr.split(",")[1]);
            Double v = ((Double) value);
            return begin <= v && v <= end;
        }
        if (value instanceof BigDecimal) {
            BigDecimal begin = new BigDecimal(rangeStr.split(",")[0]);
            BigDecimal end = new BigDecimal(rangeStr.split(",")[1]);
            BigDecimal v = ((BigDecimal) value);
            return begin.compareTo(v) <= 0 && v.compareTo(end) <= 0;
        }

        return Boolean.FALSE;
    }


    /**
     * 等价于  !Range
     *
     * @param value
     * @param rangeStr
     * @return
     */
    public static Boolean outRange(Object value, String rangeStr) {
        return !inRange(value, rangeStr);
    }


    /**
     * 判断参数的取值范围，逗号隔开，无空格；闭区间
     * 判断String的length范围, rangeStr取值举例："6,18"
     *
     * @param value
     * @param rangeStr
     * @return
     */
    public static Boolean inLength(Object value, String rangeStr) {
        if (isNull(value, rangeStr)) {
            return Boolean.FALSE;
        }
        if (null == rangeStr || "".equals(rangeStr)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {
            Integer begin = Integer.valueOf(rangeStr.split(",")[0]);
            Integer end = Integer.valueOf(rangeStr.split(",")[1]);
            Integer v = ((String) value).length();
            return begin <= v && v <= end;
        }
        return Boolean.FALSE;
    }


    /**
     * 判断参数是否在枚举的数据中, 枚举的表达式用 英文逗号隔开，无空格，如： "男,女,太监"
     * 校验过程，不在对表达式进行校验，所以请确保表达式的格式正确
     * 支持String
     * 支持Integer Short Long
     *
     * @param value
     * @param enumStr
     * @return
     */
    public static Boolean inEnum(Object value, String enumStr) {
        if (isNull(value, null)) {
            return Boolean.FALSE;
        }
        if (null == enumStr || "".equals(enumStr)) {
            return Boolean.FALSE;
        }
        String[] array = enumStr.split(",");
        Set<String> set = new HashSet<>(Arrays.asList(array));
        return set.contains(value.toString());
    }


    /**
     * 是否大于指定值
     * 支持Integer、Long、Short、Float、Double、BigDecimal
     * 支持String，判断length值
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isGreaterThan(Object value, String express) {
        if (value == null) {
            return Boolean.FALSE;
        }
        if (value instanceof Integer) {
            return ((Integer) value) > Integer.valueOf(express);
        }
        if (value instanceof Long) {
            return ((Long) value) > Long.valueOf(express);
        }
        if (value instanceof Short) {
            return ((Short) value) > Short.valueOf(express);
        }
        if (value instanceof Float) {
            return ((Float) value) > Float.valueOf(express);
        }
        if (value instanceof Double) {
            return ((Double) value) > Double.valueOf(express);
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(new BigDecimal(express)) > 0;
        }
        if (value instanceof String) {
            return ((String) value).length() > Integer.valueOf(express);
        }
        if (value instanceof Collection) {
            return ((Collection) value).size() > Integer.valueOf(express);
        }
        return Boolean.FALSE;
    }


    /**
     * 是否大于等于
     * 支持Integer、Long、Short、Float、Double、BigDecimal
     * 支持String，判断length值
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isGreaterThanEqual(Object value, String express) {
        if (value == null) {
            return Boolean.FALSE;
        }
        if (value instanceof Integer) {
            return ((Integer) value) >= Integer.valueOf(express);
        }
        if (value instanceof Long) {
            return ((Long) value) >= Long.valueOf(express);
        }
        if (value instanceof Short) {
            return ((Short) value) >= Short.valueOf(express);
        }
        if (value instanceof Float) {
            return ((Float) value) >= Float.valueOf(express);
        }
        if (value instanceof Double) {
            return ((Double) value) >= Double.valueOf(express);
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(new BigDecimal(express)) >= 0;
        }
        if (value instanceof String) {
            return ((String) value).length() >= Integer.valueOf(express);
        }
        if (value instanceof Collection) {
            return ((Collection) value).size() >= Integer.valueOf(express);
        }
        return Boolean.FALSE;

    }

    /**
     * 是否少于
     * 支持Integer、Long、Short、Float、Double、BigDecimal
     * 支持String，判断length值
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isLessThan(Object value, String express) {
        if (value == null) {
            return Boolean.FALSE;
        }
        if (value instanceof Integer) {
            return ((Integer) value) < Integer.valueOf(express);
        }
        if (value instanceof Long) {
            return ((Long) value) < Long.valueOf(express);
        }
        if (value instanceof Short) {
            return ((Short) value) < Short.valueOf(express);
        }
        if (value instanceof Float) {
            return ((Float) value) < Float.valueOf(express);
        }
        if (value instanceof Double) {
            return ((Double) value) < Double.valueOf(express);
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(new BigDecimal(express)) < 0;
        }
        if (value instanceof String) {
            return ((String) value).length() < Integer.valueOf(express);
        }
        if (value instanceof Collection) {
            return ((Collection) value).size() < Integer.valueOf(express);
        }
        return Boolean.FALSE;
    }

    /**
     * 是否少于等于
     * 支持Integer、Long、Short、Float、Double、BigDecimal
     * 支持String，判断length值
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isLessThanEqual(Object value, String express) {
        if (value == null) {
            return Boolean.FALSE;
        }
        if (value instanceof Integer) {
            return ((Integer) value) <= Integer.valueOf(express);
        }
        if (value instanceof Long) {
            return ((Long) value) <= Long.valueOf(express);
        }
        if (value instanceof Short) {
            return ((Short) value) <= Short.valueOf(express);
        }
        if (value instanceof Float) {
            return ((Float) value) <= Float.valueOf(express);
        }
        if (value instanceof Double) {
            return ((Double) value) <= Double.valueOf(express);
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(new BigDecimal(express)) <= 0;
        }
        if (value instanceof String) {
            return ((String) value).length() <= Integer.valueOf(express);
        }
        if (value instanceof Collection) {
            return ((Collection) value).size() <= Integer.valueOf(express);
        }
        return Boolean.FALSE;
    }

    /**
     * 判断是否 notEqual指定的值
     * 支持String、Integer、Long、Short、Float、Double、BigDecimal
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isNotEqual(Object value, String express) {
        return !isEqual(value, express);
    }


    /**
     * 判断是否Equal指定的值
     * 支持String、Integer、Long、Short、Float、Double、BigDecimal
     * 支持Collection，判断size的值
     *
     * @param value
     * @param express
     * @return
     */
    public static Boolean isEqual(Object value, String express) {
        if (value == null) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {
            return ((String) value).equals(express);
        }
        if (value instanceof Integer) {
            return ((Integer) value).equals(Integer.valueOf(express));
        }
        if (value instanceof Long) {
            return ((Long) value).equals(Long.valueOf(express));
        }
        if (value instanceof Short) {
            return ((Short) value).equals(Short.valueOf(express));
        }
        if (value instanceof Float) {
            return ((Float) value).equals(Float.valueOf(express));
        }
        if (value instanceof Double) {
            return ((Double) value).equals(Double.valueOf(express));
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(new BigDecimal(express)) == 0;
        }
        if (value instanceof Collection) {
            return ((Collection) value).size() == Integer.valueOf(express);
        }
        return Boolean.FALSE;
    }


    /**
     * 判断String是否满足正则表达式
     *
     * @param value
     * @param regEx 正则表达式
     * @return
     */
    public static Boolean isPattern(Object value, String regEx) {
        if (isNull(value, null)) {
            return Boolean.FALSE;
        }
        if (value instanceof String) {
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher((String) value);
            if (m.matches()) {
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }

}
//以下是Controller参数调用例子
/*
public class ParamCheckController {

    @ApiImplicitParam(name = "userId", value = "", dataType = "Integer", paramType = "query")
    @CheckParam(value = Check.NotNull, argName = "userId" )
    @PostMapping("/singleCheckNotNull")
    public Object singleCheckNotNull(Integer userId) {
        System.err.println(userId);
        return 1;
    }

    @ApiImplicitParam(name = "userName", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.NotEmpty, argName = "userName", msg = "你大爷的，这个是必填参数！")
    @PostMapping("/singleCheckNotEmpty")
    public Object singleCheckNotNull(String userName) {
        System.err.println(userName);
        return 1;
    }

    @ApiImplicitParam(name = "bl", value = "", dataType = "Boolean", paramType = "query")
    @CheckParam(value = Check.True, argName = "bl")
    @PostMapping("/singleCheckTrue")
    public Object singleCheckTrue(Boolean bl) {
        System.err.println(bl);
        return 1;
    }

    @ApiImplicitParam(name = "date", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Date, argName = "date")
    @PostMapping("/singleCheckDate")
    public Object singleCheckDate(String date) {
        System.err.println(date);
        return 1;
    }

    @ApiImplicitParam(name = "dateTime", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.DateTime, argName = "dateTime")
    @PostMapping("/singleCheckDateTime")
    public Object singleCheckDateTime(String dateTime) {
        System.err.println(dateTime);
        return 1;
    }

    @ApiImplicitParam(name = "date", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Past, argName = "date")
    @PostMapping("/singleCheckPast")
    public Object singleCheckPast(String date) {
        System.err.println(date);
        return 1;
    }

    @ApiImplicitParam(name = "dateTime", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Future, argName = "dateTime", msg = "参数必须是一个将来的日期或者时间，并且满足 yyyy-MM-dd HH:mm:ss格式")
    @PostMapping("/singleCheckFuture")
    public Object singleCheckFuture(String dateTime) {
        System.err.println(dateTime);
        return 1;
    }

    @ApiImplicitParam(name = "date", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Today, argName = "date")
    @PostMapping("/singleCheckToday")
    public Object singleCheckToday(String date) {
        System.err.println(date);
        return 1;
    }

    @ApiImplicitParam(name = "gender", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Enum, argName = "gender", express = "男,女,太监")
    @PostMapping("/singleCheckStringEnum")
    public Object singleCheckStringEnum(String gender) {
        System.err.println(gender);
        return 1;
    }

    @ApiImplicitParam(name = "gender", value = "", dataType = "Integer", paramType = "query")
    @CheckParam(value = Check.Enum, argName = "gender", express = "0,1")
    @PostMapping("/singleCheckIntegerEnum")
    public Object singleCheckIntegerEnum(Integer gender) {
        System.err.println(gender);
        return 1;
    }

    @ApiImplicitParam(name = "password", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Length, argName = "password", express = "6,18", msg = "密码length必须在6-18位之间！")
    @PostMapping("/singleCheckStringLength")
    public Object singleCheckStringLength(String password) {
        System.err.println(password);
        return 1;
    }

    @ApiImplicitParam(name = "password", value = "", dataType = "String", paramType = "query")
    @CheckParams({
            @CheckParam(value = Check.ge, argName = "password", express = "6"),
            @CheckParam(value = Check.le, argName = "password", express = "18")
    })
    @PostMapping("/singleCheckStringLength1")
    public Object singleCheckStringLength1(String password) {
        System.err.println(password);
        return 1;
    }

    @ApiImplicitParam(name = "age", value = "", dataType = "Integer", paramType = "query")
    @CheckParam(value = Check.Range, argName = "age", express = "18,50")
    @PostMapping("/singleCheckIntegerRange")
    public Object singleCheckIntegerRange(Integer age) {
        System.err.println(age);
        return 1;
    }

    @ApiImplicitParam(name = "age", value = "", dataType = "Integer", paramType = "query")
    @CheckParams({
            @CheckParam(value = Check.ge, argName = "age", express = "18"),
            @CheckParam(value = Check.le, argName = "age", express = "50")
    })
    @PostMapping("/singleCheckIntegerRange1")
    public Object singleCheckIntegerRange1(Integer age) {
        System.err.println(age);
        return 1;
    }

    @ApiImplicitParam(name = "age", value = "", dataType = "Integer", paramType = "query")
    @CheckParam(value = Check.NotIn, argName = "age", express = "18,50")
    @PostMapping("/singleCheckIntegerNotIn")
    public Object singleCheckIntegerNotIn(Integer age) {
        System.err.println(age);
        return 1;
    }

    @ApiImplicitParam(name = "age", value = "", dataType = "Integer", paramType = "query")
    @CheckParams({
            @CheckParam(value = Check.lt, argName = "age", express = "18"),
            @CheckParam(value = Check.gt, argName = "age", express = "50")
    })
    @PostMapping("/singleCheckIntegerNotIn1")
    public Object singleCheckIntegerNotIn1(Integer age) {
        System.err.println(age);
        return 1;
    }

    @ApiImplicitParam(name = "email", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Email, argName = "email", msg = "你大爷的，输入个邮箱啊！")
    @PostMapping("/singleCheckEmail")
    public Object singleCheckEmail(String email) {
        System.err.println(email);
        return 1;
    }

    @ApiImplicitParam(name = "age", value = "", dataType = "Integer", paramType = "query")
    @CheckParam(value = Check.ge, argName = "age", express = "18", msg = "必须大于等于18岁") // gt、lt、le、ne、Equal不再举例; 具体看注释
    @PostMapping("/singleCheckIntegerGe")
    public Object singleCheckIntegerGe(Integer age) {
        System.err.println(age);
        return 1;
    }

    @ApiImplicitParam(name = "pattern", value = "", dataType = "String", paramType = "query")
    @CheckParam(value = Check.Pattern, argName = "pattern", express = "^[\u0021-\u007E]{4,16}$")
    @PostMapping("/singleCheckPattern")
    public Object singleCheckPattern(String pattern) {
        System.err.println(pattern);
        return 1;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userName", dataType = "String", paramType = "query")
    })
    @CheckParams({
            @CheckParam(value = Check.NotNull, argName = "userId", msg = "你大爷的，这个是必填参数！"),
            @CheckParam(value = Check.NotNull, argName = "userName")
    })
    @PostMapping("/multiCheckNotNull")
    public Object multiCheckNotNull(Integer userId, String userName) {
        System.err.println(userId);
        System.err.println(userName);
        return 1;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userName", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "employee", dataType = "entity", paramType = "body")
    })
    @CheckParams({
            @CheckParam(value = Check.NotNull, argName = "userId", msg = "你大爷的，这个是必填参数！"),
            @CheckParam(value = Check.NotEmpty, argName = "userName"),
            @CheckParam(value = Check.NotEmpty, argName = "employee.name")
    })
    @PostMapping("/entityCheckNotNull")
    public Object entityCheckNotNull(Integer userId, String userName, @RequestBody EmployeeEntity employee) {
        System.err.println(userId);
        System.err.println(userName);
        System.err.println(employee.getName());
        return 1;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userName", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dept", dataType = "entity", paramType = "body")
    })
    @CheckParams({
            @CheckParam(value = Check.NotNull, argName = "userId", msg = "你大爷的，这个是必填参数！"),
            @CheckParam(value = Check.NotEmpty, argName = "userName"),
            @CheckParam(value = Check.NotEmpty, argName = "dept.deptName"),
            @CheckParam(value = Check.Past, argName = "dept.createTime"),
            @CheckParam(value = Check.lt, argName = "dept.employees", express = "2") // 对集合的size判断
    })
    @PostMapping("/entityMultiCheck")
    public Object entityMultiCheck(Integer userId, String userName, @RequestBody DeptEntity dept) {
        System.err.println(userId);
        System.err.println(userName);
        System.err.println(dept.getDeptName());
        return 1;
    }

}
 */